<template>
  <div>
    <Search
      @handleSearch="getList"
      @handleAdd="handleAdd"
      :queryParams="queryParams"
      :btnLoading="btnLoading"
    ></Search>
    <List :list="list" :queryParams='queryParams'></List>
    <el-row type="flex" justify="end" style="margin-top: 10px">
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-row>
  </div>
</template>
<script>
import Search from './modules/Search.vue';
import List from './modules/List.vue';
import { Reimbursement } from '@/api/approve.js';
export default {
  data () {
    return {
      createTime: [],
      flowStatus: undefined,
      btnLoading: false,
      list: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      total: 0,
      flowStatusList: [
        { id: 0, name: '已提交' },
        { id: 1, name: '审批中' },
        { id: 2, name: '已拒绝' },
        { id: 3, name: '已完成' },
        { id: 4, name: '终止' },
        { id: 5, name: '撤销' }
      ]
    };
  },
  components: {
    Search,
    List
  },
  created () {
    this.getList()
  },
  methods: {
    handleSearch () {},
    handleAdd () {
      this.$router.push('/Reimbursement/Add')
    },
    // 列表
    getList () {
      Reimbursement.list(this, {
        pageParam: {
          pageNum: this.queryParams.pageNum,
          pageSize: this.queryParams.pageSize
        },
        flowWorkOrderDtoFilter: {
          flowStatus: this.queryParams.flowStatus,
          createTimeStart: this.queryParams.time && this.queryParams.time[0],
          createTimeEnd: this.queryParams.time && this.queryParams.time[1]
        },
        orderParam: [
          {
            fieldName: 'createTime',
            asc: false
          }
        ]
      }).then(res => {
        this.list = res.data.dataList
        this.total = res.data.totalCount
        this.list.forEach((item) => {
          this.$set(item, 'flowStatusName', this.flowStatusList[item.flowStatus].name)
        })
      })
    },
    submitForm () {
      console.log(this.form)
      let begin = new Date(this.form.startTime).getTime()
      let end = new Date(this.form.endTime).getTime()
      let intervalTime = end - begin
      console.log(intervalTime)
    }
  }
};
</script>
<style scoped>
</style>
